<?php
defined('IN_SITE') or exit('Access Denied');

$M = include(MOD_ROOT.'sign/config.inc.php'); //aming
require_once 'sign.class.php';
$sign = new sign();
require_once MOD_ROOT.'attachment/attachment.class.php';
$attachment = new attachment($module, $catid);
$C = subcat('sign');

switch($action)
{
    default:
		
		if($signid){
			// 如果参数是自定义名称
			if(!$signid && $prefix){
				$result = $db->get_one("select `signid` from ".DB_PRE."sign where prefix = '$prefix'");
				$signid = $result['signid'];
				unset($result);
			} 
			
			// 主要获取该文章的栏目所在信息，例如详细页模板等等
			require_once 'sign.class.php';
			$sign = new sign();
			$r = $sign->get($signid);
			$C = cache_read('category_'.$r['catid'].'.php');
		
		 
			
			
			// 获取该文章的所有内容信息
			require_once 'model/sign_output.class.php';
			$out = new sign_output();
			$data = $out->get($r);
			extract($data);
		
			// 设置文章的头部信息、关键字等
			$title = strip_tags($title);
			$head['title'] = $title.'_'.$C['catname'].'_'.$SETTING['sitename'];
			$head['keywords'] = str_replace(' ', ',', $r['keywords']);
			$head['description'] = $r['description'];
			 
			if(!$C['defaultchargepoint'] && !$r['readpoint'])
			{
				header('Last-Modified: '.gmdate('D, d M Y H:i:s', $r['updatetime']).' GMT');
				header('Expires: '.gmdate('D, d M Y H:i:s', $r['updatetime']+CACHE_PAGE_CONTENT_TTL).' GMT');
				header('Cache-Control: max-age='.CACHE_PAGE_CONTENT_TTL.', must-revalidate');
			}
			include template('view.html','sign');
			cache_page(CACHE_PAGE_CONTENT_TTL);
		}
		else{
			$head['title'] = $M['seo_title'];
			$head['keywords'] = $M['seo_keywords'];
			$head['description'] = $M['seo_description'];
			
			$ttl = $child == 1 ? CACHE_PAGE_CATEGORY_TTL : CACHE_PAGE_LIST_TTL;
			header('Last-Modified: '.gmdate('D, d M Y H:i:s', TIME).' GMT');
			header('Expires: '.gmdate('D, d M Y H:i:s', TIME + $ttl).' GMT');
			header('Cache-Control: max-age='.$ttl.', must-revalidate');
			include template('index.html','sign');
		}
	break; 
	
	case 'tag':
		$tag = $tag ? $tag : $name;
		$head['title'] = $tag.'-'.$SETTING['sitename'];
		include template('tag.html','sign');
	break;
	
	case 'add':
		if($dosubmit)
		{
			$info['catid'] = $catid;
			$info['status'] = 99;
			if(isset($info['inputtime'])) $info['updatetime'] = $info['inputtime'];
			$signid = $sign->add($info,$cat_selected);
			if($signid) showmessage('发布成功！', url("?module=$module&action=sign"));
		}
		else{
			$modelid = 55;
			require_once 'form.class.php';
			require 'model/sign_form.class.php';
			$sign_form = new sign_form($modelid);
			$data['catid'] = $catid;
			$forminfos = $sign_form->get($data);
			
			//dump($forminfos);
			include template('add.html','sign');
		}
	break;
	
	// 点击率，调用方法
	//<script language="JavaScript" src="?module=codex&action=count&codexid={$codexid}">...
	case 'count':
		if($signid)
		{
			$signid = intval($signid);
			$r = $db->get_one("SELECT * FROM `".DB_PRE."sign` WHERE `signid`=$signid");
			if(!$r) return false;
			$hits = $r['hits'] + 1;
			return $db->query("UPDATE `".DB_PRE."sign` SET `hits`=$hits WHERE `signid`=$signid");
			
		}
		echo "\$('#hits').html($hits)";
	break;
	
	
	// ajax送花
	case 'flower':
		$signid = $_GET['id'] ? $_GET['id'] : $_POST['id'];
		if($signid)
		{
			$signid = intval($signid);
			$r = $db->get_one("SELECT `flower` FROM `".DB_PRE."sign` WHERE `signid`=$signid");
			if(!$r) return false;
			$flower = $r['flower'] + 1;
			$db->query("UPDATE `".DB_PRE."sign` SET `flower`=$flower WHERE `signid`=$signid");
			
		}
		echo $flower;
	break;
	
	// ajax砸蛋
	case 'egg':
		$signid = $_GET['id'] ? $_GET['id'] : $_POST['id'];
		if($signid)
		{
			$signid = intval($signid);
			$r = $db->get_one("SELECT `egg` FROM `".DB_PRE."sign` WHERE `signid`=$signid");
			if(!$r) return false;
			$egg = $r['egg'] + 1;
			$db->query("UPDATE `".DB_PRE."sign` SET `egg`=$egg WHERE `signid`=$signid");
			
		}
		echo $egg;
	break;
	
}
?>